package com.jt.msg;

/**
 * 数据报头
 *
 * @author wang xiao
 * date 2023/8/9
 */
public class PacketHeader {
    /**
     * 消息ID 2字节
     */
    private short msgId;

    /**
     * 消息体属性 2字节
     */
    private short msgBodyProps;

    /**
     * 终端ID号 6字节
     */
    private String terminalId;

    /**
     * 流水号 2字节
     */
    private short flowId;

    /**
     * 获取包体长度
     *
     * @return short
     */
    public short getMsgBodyLength() {
        return (short) (msgBodyProps & 0x3ff);
    }

    /**
     * 获取加密类型 3bits
     *
     * @return byte
     */
    public byte getEncryptionType() {
        return (byte) ((msgBodyProps & 0x1c00) >> 10);
    }

    /**
     * 是否分包
     *
     * @return boolean
     */
    public boolean hasSubPackage() {
        return ((msgBodyProps & 0x2000) >> 13) == 1;
    }

    public short getMsgId() {
        return msgId;
    }

    public void setMsgId(short msgId) {
        this.msgId = msgId;
    }

    public short getMsgBodyProps() {
        return msgBodyProps;
    }

    public void setMsgBodyProps(short msgBodyProps) {
        this.msgBodyProps = msgBodyProps;
    }

    public String getTerminalId() {
        return terminalId;
    }

    public void setTerminalId(String terminalId) {
        this.terminalId = terminalId;
    }

    public short getFlowId() {
        return flowId;
    }

    public void setFlowId(short flowId) {
        this.flowId = flowId;
    }
}
